package com.dmgis.hndz.common.utils;

import com.dmgis.entity.DmMapServiceInfo;
import com.dmgis.entity.DmsLayer;
import com.dmgis.hndz.pojo.*;
import com.dmgis.service.DmServiceConnector;
import com.dmgis.service.MapXML;


import java.util.ArrayList;
import java.util.List;

public class LayerUtil {

    /**
     * 获取所有图层名称
     * @param ip
     * @param port
     * @param serveName
     * @return
     */
    public static List<String> getAllLayerName(String ip, String port, String serveName){
        try {
            // 创建DmServiceConnector实例，连接到指定的服务地址和端口
            DmServiceConnector conn = new DmServiceConnector(ip, port);

            String res = conn.getServiceXml(serveName, 6, "");

            // 输出服务器返回的XML数据
            System.out.println(res);

            // 创建MapXML实例，用于解析XML数据
            MapXML mapXML = new MapXML();

            // 解析XML数据为DmMapServiceInfo实体类
            DmMapServiceInfo dmMapServiceInfo = mapXML.dmGetProjServers(res);

            List<String> layerNameList = new ArrayList<>();

            // 输出解析后的实体类信息
            System.out.println(dmMapServiceInfo);
            List<DmsLayer> layers = dmMapServiceInfo.getLayers();
            for (DmsLayer layer : layers) {
                String name = layer.getName();
                layerNameList.add(name);
            }

            return layerNameList;
        } catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }

    /**
     * 获取图层对象
     *
     * @param layerName
     * @return
     */
    public static Class getLayerClass(String layerName) {
        List<Object> layerObject = new ArrayList<>();
        Class objectClass = null;
        switch (layerName) {
            case "村点":
                objectClass = VillagePointLayer.class;
                break;
            case "乡界面":
                objectClass = TownshipLayer.class;
                break;
            case "铁路":
                objectClass = RailwayLayer.class;
                break;
            case "乡村道路":
                objectClass = CountryRoadLayer.class;
                break;
            case "国道":
                objectClass = NationalRoadLayer.class;
                break;
            case "省道":
                objectClass = ProvincialRoadLayer.class;
                break;
            case "高速":
                objectClass = HighwayLayer.class;
                break;
            case "县道":
                objectClass = CountyRoadLayer.class;
                break;
            case "水系":
                objectClass = WaterSystemLayer.class;
                break;
            case "灾害点":
                objectClass = PotentialPoints.class;
                break;
            case "重要目标":
                objectClass = ImpGoal.class;
                break;
            case "危险源":
                objectClass = DangerSource.class;
                break;
            case "易涝点":
                objectClass = WaterLoggingPointInfo.class;
                break;
            case "历史火点":
                objectClass = FireHistory.class;
                break;
            case "县界面":
                objectClass = XianJieMian.class;
                break;
        }
        return objectClass;
    }
}
